package com.unicorn.vo;

import com.unicorn.entity.enums.SupportFileType;
import com.unicorn.util.common.MD5Tool;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * Created by user on 2016/12/4.
 */
public class FileVO extends BaseFileVO {

    private String fileName;

    private String perfix;

    private Long fileSize;

    private String filePath;

    /**
     * 文件/目录 父级目录
     */
    private String parentPath;

    private Boolean isFile;

    private   String fileFullPath=filePath+"/"+fileName;
    /**
     * 文件二进制流
     */
    private InputStream fileIns;
    /**
     * 文件类型
     */
    @Enumerated(EnumType.STRING)
    private SupportFileType fileType;



    @DateTimeFormat(pattern = "yyyy-MM-DD HH:mm:ss")
    private String createDate;

    @DateTimeFormat(pattern = "yyyy-MM-DD HH:mm:ss")
    private String updateDate;

    public String getParentPath() {
        return parentPath;
    }

    public void setParentPath(String parentPath) {
        this.parentPath = parentPath;
    }

    public String getFileFullPath() {
        if(fileFullPath==null){
            fileFullPath=filePath+fileName+perfix;
        }
        return fileFullPath;
    }

    public void setFileFullPath(String fileFullPath) {
        this.fileFullPath = fileFullPath;
    }

    public Boolean getFile() {
        return isFile;
    }

    public void setFile(Boolean isFile) {
        this.isFile = isFile;
    }

    public SupportFileType getFileType() {
        return fileType;
    }

    public void setFileType(SupportFileType fileType) {
        this.fileType = fileType;
    }

    public InputStream getFileIns() {

        return fileIns;
    }

    public void setFileIns(InputStream fileIns) {
        this.fileIns = fileIns;
    }

    @Override
    public int hashCode() {

        File targetFile=new File(fileFullPath);
        if(!targetFile.exists() ||!targetFile.isFile()){
            try {
                throw  new FileNotFoundException(targetFile.getAbsolutePath()+"不存在");
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
         return    MD5Tool.getMD5(targetFile).hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        return super.equals(obj);
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getPerfix() {
        return perfix;
    }

    public void setPerfix(String perfix) {
        this.perfix = perfix;
    }

    public Long getFileSize() {
        return fileSize;
    }

    public void setFileSize(Long fileSize) {
        this.fileSize = fileSize;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public String getCreateDate() {
        return createDate;
    }

    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }

    public String getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(String updateDate) {
        this.updateDate = updateDate;
    }



}
